﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Data;
using System.Data.SqlClient;

/// <summary>
/// Summary description for clsLOP
/// </summary>
public class clsLOP
{
	public clsLOP()
	{
		//
		// TODO: Add constructor logic here
		//
    }

    #region Select Lớp học
    public DataTable Select()
    {
        DataTable dt = new DataTable();
        DatabaseConnect connect = new DatabaseConnect();
        try
        {
            dt = connect.GetSelectCommand("LOP_Select", null);
        }
        catch 
        {
            dt = null;
        }
        return dt;
    }
    #endregion

    #region Insert Lớp học
    public void Insert(string malop, DateTime ngaykhaigiang, string thoikhoabieu, string mach, int thangthu, string tgthuphi, string macn)
    {
        DatabaseConnect connect = new DatabaseConnect();
        // Tham so
        SqlParameter[] para = new SqlParameter[7];
        para[0] = new SqlParameter("@malop", malop);        
        para[1] = new SqlParameter("@ngaykg", ngaykhaigiang);
        para[2] = new SqlParameter("@tghoc", thoikhoabieu);
        para[3] = new SqlParameter("@mach", mach);
        para[4] = new SqlParameter("@thangthu", thangthu);
        para[5] = new SqlParameter("@tgthuphi", tgthuphi);
        para[6] = new SqlParameter("@macn", macn);

        try
        {
            connect.ExecuteQuery("LOP_Insert", para);
        }
        catch
        { }
    }
    #endregion

    #region Update Lớp học
    public void Update(string malop, DateTime ngaykhaigiang, string thoikhoabieu, bool ketthuc, string mach, int thangthu, string tgthuphi, string macn)
    {
        DatabaseConnect connect = new DatabaseConnect();
        // Tham so
        SqlParameter[] para = new SqlParameter[8];
        para[0] = new SqlParameter("@malop", malop);       
        para[1] = new SqlParameter("@ngaykg", ngaykhaigiang);
        para[2] = new SqlParameter("@tghoc", thoikhoabieu);
        para[3] = new SqlParameter("@kt", ketthuc);
        para[4] = new SqlParameter("@mach", mach);
        para[5] = new SqlParameter("@thangthu", thangthu);
        para[6] = new SqlParameter("@tgthuphi", tgthuphi);
        para[7] = new SqlParameter("@macn", macn);

        try
        {
            connect.ExecuteQuery("LOP_Update", para);
        }
        catch
        { }
    }
    #endregion

    #region Delete Lớp học
    public void Delete(string malop)
    {
        DatabaseConnect connect = new DatabaseConnect();

        // Tham so
        SqlParameter[] para = new SqlParameter[1];
        para[0] = new SqlParameter("@malop", malop);

        try
        {
            connect.ExecuteQuery("LOP_Delete",para);
        }
        catch{}
    }
    #endregion

    #region Get By Chuyen Nganh
    public static DataTable GetByChuyenNganh(string F_MACHN, string F_MACN)
    {
        DataTable dt = new DataTable();
        DatabaseConnect connect = new DatabaseConnect();
        SqlParameter[] para = new SqlParameter[2];

        para[0] = new SqlParameter("@F_MACHN", F_MACHN);
        para[1] = new SqlParameter("@F_MACN", F_MACN);
        try
        {
            dt = connect.GetSelectCommand("LOP_GetByChuyenNganh", para);
        }
        catch
        {
           // dt = null;
        }
        return dt;
    }
    #endregion

    #region Get By Chi Nhanh
    public static DataTable GetByChiNhanh(string F_MACN)
    {
        DataTable dt = new DataTable();
        DatabaseConnect connect = new DatabaseConnect();
        // Tham so
        SqlParameter[] para = new SqlParameter[1];
        para[0] = new SqlParameter("@F_MACN", F_MACN);
        try
        {
            dt = connect.GetSelectCommand("LOP_GetByChiNhanh", para);
        }
        catch { }
        return dt;
    }
    #endregion
    #region Get By Chi Nhanh in Task Chuyen lop
    public static DataTable GetByChiNhanh_inTaskChuyenlop(string F_MACN)
    {
        DataTable dt = new DataTable();
        DatabaseConnect connect = new DatabaseConnect();
        // Tham so
        SqlParameter[] para = new SqlParameter[1];
        para[0] = new SqlParameter("@F_MACN", F_MACN);
        try
        {
            dt = connect.GetSelectCommand("LOP_GetByChiNhanh_inTaskChuyenlop", para);
        }
        catch { }
        return dt;
    } 
    #endregion
    #region Get By Chi Nhanh 1
    public static DataTable GetByChiNhanh1(string F_MACN)
    {
        DataTable dt = new DataTable();
        DatabaseConnect connect = new DatabaseConnect();
        // Tham so
        SqlParameter[] para = new SqlParameter[1];
        para[0] = new SqlParameter("@F_MACN", F_MACN);
        try
        {
            dt = connect.GetSelectCommand("LOP_GetByChiNhanh1", para);
        }
        catch { }
        return dt;
    }
    #endregion

    public static DataTable GetByChiNhanh1_baocao(string F_MACN)
    {
        DataTable dt = new DataTable();
        DatabaseConnect connect = new DatabaseConnect();
        // Tham so
        SqlParameter[] para = new SqlParameter[1];
        para[0] = new SqlParameter("@F_MACN", F_MACN);
        try
        {
            dt = connect.GetSelectCommand("LOP_GetByChiNhanh1_baocao", para);
        }
        catch { }
        return dt;
    }

    #region Get By Id
    public static DataTable GetById(string F_MALOP)
    {
        DataTable dt = new DataTable();
        DatabaseConnect connect = new DatabaseConnect();
        // Tham so 
        SqlParameter[] para = new SqlParameter[1];
        para[0] = new SqlParameter("@F_MALOP", F_MALOP);
        try
        {
            dt = connect.GetSelectCommand("LOP_GetById", para);
        }
        catch
        { }

        return dt;
    }
    #endregion

    #region Giảm Sĩ Số
    public static void DecreaseCount(string F_MALOP)
    {
        DatabaseConnect connect = new DatabaseConnect();

        // Tham so
        SqlParameter[] para = new SqlParameter[1];
        para[0] = new SqlParameter("@F_MALOP", F_MALOP);

        try
        {
            connect.ExecuteQuery("LOP_GiamSiSo", para);
        }
        catch { }
    }
    #endregion

    #region Tăng Sĩ Số
    public static void IncreaseCount(string F_MALOP)
    {
        DatabaseConnect connect = new DatabaseConnect();

        // Tham so
        SqlParameter[] para = new SqlParameter[1];
        para[0] = new SqlParameter("@F_MALOP", F_MALOP);

        try
        {
            connect.ExecuteQuery("LOP_TangSiSo", para);
        }
        catch { }
    }
    #endregion

    #region Lấy Thời Khóa Biểu
    public static string GetSchedule(string F_MALOP)
    {
        DataTable dt = GetById(F_MALOP);
        if (dt.Rows.Count > 0)
        {
            return dt.Rows[0]["F_TGHOC"].ToString();
        }
        else
        {
            return "";
        }
    }
    #endregion

}